package com.hq.fxh.No3_TuiGuang.Adaoter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.hq.fxh.Modle.GetPushDataRes;
import com.hq.fxh.R;

import java.util.Calendar;
import java.util.List;


/**
 * @author 小谢
 * @ClassName PushStatisticDataFragmentAdapter
 * @Description :
 * @Created 2017/5/22 0022
 */

public class PushStatisticDataFragmentAdapter extends RecyclerView.Adapter<PushStatisticDataFragmentAdapter.ViewHolder> {
    private List<GetPushDataRes.DataBean> list;
    private int exportOrClick;//0曝光 1点击
    private int dateType;
    private int clickPosotion;
    private Context context;

    public PushStatisticDataFragmentAdapter(Context context, List<GetPushDataRes.DataBean> list, int exportOrClick, int dateType, int clickPosition) {
        this.context = context;
        this.list = list;
        this.clickPosotion = clickPosition;
        this.dateType = dateType;
        this.exportOrClick = exportOrClick;
    }

    @Override
    public PushStatisticDataFragmentAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.layout_item_push, viewGroup, false);
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }

    @Override
    public void onBindViewHolder(PushStatisticDataFragmentAdapter.ViewHolder holder, int position) {
        holder.time.setText(list.get(position).getDate());
        if (exportOrClick == 0) {//曝光
            holder.count.setText("曝光 " + list.get(position).getLook());
        } else {//点击
            holder.count.setText("点击 " + list.get(position).getClick());
        }
        //获取当前月份
        Calendar cal = Calendar.getInstance();
        int month = cal.get(Calendar.MONTH) + 1;
        int time = Integer.parseInt(list.get(position).getDate());
        String strTime, strNextTime;
        if (time < 10) {
            strTime = "0" + time;
        } else {
            strTime = "" + time;
        }
        int timNext = time + 1;
        if (timNext < 10) {
            strNextTime = "0" + timNext;
        } else {
            strNextTime = "" + timNext;
        }
        if (dateType == 1) {//今日
            holder.time.setText(strTime + ":00-" + strNextTime + ":00");
        } else if (dateType == 2) {//本月
            holder.time.setText(month + "月" + time + "日");
        }
        if (position == clickPosotion) {
            holder.time.setTextColor(context.getResources().getColor(R.color.new_red));
        } else {
            holder.time.setTextColor(context.getResources().getColor(R.color.black3));
        }
    }

    @Override
    public int getItemCount() {
        return list.isEmpty() ? 0 : list.size();
    }

    public void setDate(List<GetPushDataRes.DataBean> dataList,int ecportOrClick, int dateType, int finalI){
        list=dataList;
        exportOrClick=ecportOrClick;
        this.dateType =dateType;
        clickPosotion =finalI;
        notifyDataSetChanged();
    }
    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView time, count;

        public ViewHolder(View itemView) {
            super(itemView);
            time = (TextView) itemView.findViewById(R.id.time);
            count = (TextView) itemView.findViewById(R.id.count);
        }
    }
}
